package com.test.rabbitmq.config;

import org.springframework.amqp.core.*;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;

/**
 * @ClassName RabbitMQConfig
 * @Author lulei
 * @Data 2020/3/12 21:48
 */


@SpringBootConfiguration
public class RabbitMQConfig {

    @Bean
    public Queue queueWork1() {

        return new Queue("queue-NO:10001");
    }

    @Bean
    public Queue queueWork2() {

        return new Queue("queue-NO:10002");
    }

    @Bean
    public Queue queueWork3() {

        return new Queue("queue-NO:10003");
    }

    @Bean
    public FanoutExchange fanoutExchange1() {

        return new FanoutExchange("exchange-NO:20001");
    }

    /**
     *
     * 将队列绑定到交换机
     *
     * @param queueWork2 queue-NO:10002
     * @param fanoutExchange1  exchange-NO:20001
     * @return
     */
    @Bean
    public Binding bindingExchange1(Queue queueWork2,FanoutExchange fanoutExchange1){
        return BindingBuilder.bind(queueWork2).to(fanoutExchange1);
    }

    /**
     *
     * 将队列绑定到交换机
     *
     * @param queueWork3 queue-NO:10003
     * @param fanoutExchange1 exchange-NO:20001
     * @return
     */
    @Bean
    public Binding bindingExchange2(Queue queueWork3,FanoutExchange fanoutExchange1){
        return BindingBuilder.bind(queueWork3).to(fanoutExchange1);
    }
}
